package com.rabbitmq.learn.tx;

import com.rabbitmq.client.*;
import com.rabbitmq.learn.common.ConnectionUtils;
import com.rabbitmq.learn.common.RabbitMqConstant;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by Lxk on 2019/8/11.
 */
public class Receiver {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection con = ConnectionUtils.getConnection();

        Channel channel = con.createChannel();

        channel.queueDeclare(RabbitMqConstant.TxSimple.QUEUE_TX_SIMPLE, false, false, false, null);

        DefaultConsumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String msg = new String(body, "utf-8");
                System.out.println("msg:" + msg);
            }
        };

        channel.basicConsume(RabbitMqConstant.TxSimple.QUEUE_TX_SIMPLE, true, consumer);

    }

}
